<%//if ( session.getAttribute("user")!=null && ((framework.bean.User)session.getAttribute("user")).getProfil()==framework.bean.User.PROFIL_ADMIN ){%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.util.Hashtable,java.util.Vector,framework.database.DBAccess"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
		<title>JDBC</title>
	</head>
	
	<style type="text/css" rev=stylesheet media=screen><!-- 
		textarea { 
		  font-size: 10px; 
		  text-align: left; 
		  color: black; 
		  font-family: arial, helvetica, sans-serif; 
		}
	--></style>
	
	<body>
		<font face=Verdana,Arial,Helvetica,sans-serif size=1>
		<form name="formjdbc" method="POST" action="jdbc.jsp">
		<table border=1 cellpadding=3 cellspacing=0>
			<tr>
				<td valign="top"><font face=Verdana,Arial,Helvetica,sans-serif size=1><input type="radio" name="type" value="pool" <%="direct".equals(request.getParameter("type"))?"":"checked"%>>Pool Connection</font></td>
				<td>
					<table border=0 cellpadding=5 cellspacing=0 width="100%">
						<tr>
							<td align="right" width="100%"><font face=Verdana,Arial,Helvetica,sans-serif size=1>pool</font></td>
							<td><input type="text" size="60" name="pool" value="<%=request.getParameter("pool")!=null?request.getParameter("pool"):"java:/comp/env/jdbc/pool"%>"></td>
						</tr>
					</table>
				</td>
				<td><font face=Verdana,Arial,Helvetica,sans-serif size=1>DBCP pool : java:/comp/env/mypool<br>JBoss pool : java:/mypool</font></td>
			</tr>
  			<tr>
  				<td valign="top"><font face=Verdana,Arial,Helvetica,sans-serif size=1><input type="radio" name="type" value="direct" <%="direct".equals(request.getParameter("type"))?"checked":""%>>Direct Connection</font></td>
				<td>
					<table border=0 cellpadding=5 cellspacing=0>
						<tr>
							<td align="right"><font face=Verdana,Arial,Helvetica,sans-serif size=1>driver</font></td>
							<td><input type="text" size="60" name="driver" value="<%=request.getParameter("driver")!=null?request.getParameter("driver"):"org.postgresql.Driver"%>"></td>
						</tr>
						<tr>
							<td align="right"><font face=Verdana,Arial,Helvetica,sans-serif size=1>url</font></td>
							<td><input type="text" size="60" name="url" value="<%=request.getParameter("url")!=null?request.getParameter("url"):"jdbc:postgresql://localhost:5432/FRAMEWORKDB"%>"></td>
						</tr>
  						<tr>
							<td align="right"><font face=Verdana,Arial,Helvetica,sans-serif size=1>user</font></td>
							<td><input type="text" size="60" name="user" value="<%=request.getParameter("user")!=null?request.getParameter("user"):"fwbd"%>"></td>
						</tr>
  						<tr>
							<td align="right"><font face=Verdana,Arial,Helvetica,sans-serif size=1>password</font></td>
							<td><input type="text" size="60" name="password" value="<%=request.getParameter("password")!=null?request.getParameter("password"):"fwbd"%>"></td>
						</tr>
					</table>
				</td>
				<td>
					<font face=Verdana,Arial,Helvetica,sans-serif size=1>
						oracle.jdbc.driver.OracleDriver<br>
						net.sourceforge.jtds.jdbc.Driver<br>
						org.postgresql.Driver<br>
						com.mysql.jdbc.Driver<br>
						<br>
						jdbc:oracle:thin:myschema@localhost:1521:mysid<br>
						jdbc:jtds:sqlserver://localhost:1433/mydatabase<br>
						jdbc:postgresql://localhost:5432/mydatabase<br>
						jdbc:mysql://localhost:3306/mydatabase?autoReconnect=true
					</font>
				</td>
			</tr>

  		</table>
  			<br><br>
  			request&nbsp;&nbsp;<br>
  			<textarea rows="20" cols="200" name="request" class=textarea><%=request.getParameter("request")!=null?request.getParameter("request"):"select tablename from pg_tables where schemaname='public' order by 1"%></textarea>
  			<br><br><br>
  			<input type="submit" name="submit" value="Execute">
  			<input type="submit" name="submit" value="Update">
  			<br><br>
		</form>
		
<%
	if (request.getParameter("request")!=null) {
	    DBAccess dBAccess;
	    if ("direct".equals(request.getParameter("type")))
	    	dBAccess = new DBAccess(request.getParameter("driver"),request.getParameter("url"),request.getParameter("user"),request.getParameter("password"),false);
	    else
	        dBAccess = new DBAccess(request.getParameter("pool"),false);
	    
		Hashtable hashtableResult = null;
		int rowCount = -1;
		if ("Execute".equals(request.getParameter("submit")))
		        hashtableResult = dBAccess.processQuery(request.getParameter("request"));
		else if ("Update".equals(request.getParameter("submit")))
		    	rowCount = dBAccess.processUpdate(request.getParameter("request"));
		
		if (dBAccess.getLog()!=null && dBAccess.getLog().size()>0) {
		    out.println("<textarea rows=\"5\" cols=\"200\" class=textarea>");
			for(int i=0;i<dBAccess.getLog().size();i++) {
			    out.println(dBAccess.getLog().elementAt(i));
			}
			out.println("</textarea><br>");
		}
		
		if (hashtableResult!=null) {
			Vector labels = (Vector)hashtableResult.get("labels");
			Vector results = (Vector)hashtableResult.get("results");
			out.println("<br>colcount = " + labels.size() + "<br>rowcount = " + results.size() + "<br><br>");
			out.println("<table border=1 cellpadding=1 cellspacing=1> <tr>");
			for(int i=0;i<labels.size();i++)
	       		out.println("<td><b><font face=Verdana,Arial,Helvetica,sans-serif size=1>&nbsp;"+labels.elementAt(i)+"&nbsp;</font></b></td>");
			out.println("</tr>");
			Hashtable record;
			for(int i=0;i<results.size();i++) {
				record = (Hashtable)results.elementAt(i);
	        	out.println("<tr>");
				for(int j=0;j<labels.size();j++)
					out.println("<td><font face=Verdana,Arial,Helvetica,sans-serif size=1>&nbsp;"+record.get((String)labels.elementAt(j))+"&nbsp;</font></td>");
				out.println("</tr>");
			}
			out.println("</table>");
		}
		
		if (rowCount!=-1) {
			out.println("<br>rowcount = " + rowCount + "<br>");
		}
	}
%>

		</font>
	</body>
</html>

<%//}%>